﻿using GetMan.Core.DB.Entities;
using System.ComponentModel.Composition;

namespace GetMan.Core.DB.Services.WorkSpace
{
    /// <summary>
    /// 工作区域
    /// </summary>
    [Export(typeof(IWorkSpaceService))]
    public class WorkSpaceService : BaseService<WorkSpaceEntity>, IWorkSpaceService
    {
        [ImportingConstructor]
        public WorkSpaceService(IFreeSql freeSql) : base(freeSql)
        {

        }

        /// <summary>
        /// 更新选中ID
        /// </summary>
        /// <param name="id">选中的id</param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public bool UpdateSelected(long id)
        {
            _freeSql.Update<WorkSpaceEntity>()
                .Where(x => x.Id != id)
                .Set(x => x.IsSelected, false)
                .ExecuteAffrows();

            return _freeSql.Update<WorkSpaceEntity>()
                .Where(x => x.Id == id)
                .Set(x => x.IsSelected, true)
                .ExecuteAffrows() > 0;
        }
    }
}